Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next
Subject: Xpages/JSF, with this Backing Bean, I thee Wed
Feedback Type: Suggestion
Product Area: Domino Designer on Eclipse (DDE)
Technical Area: Application Development
Platform: Windows
Release: 8.5.2
Reproducible: Always

Knowledge Sharing:

Should you need a bit of assistance getting Java code to play nice with Xpages, look to JSF samples... Below is straight forward and will be preliminary to most developers. Included are two samples, one of which is an original, the other is its fruit. We will begin by adding code this sample is based on, courtesy of: http://www.roseindia.net/jsf/data.shtml, the sample is a JavaBean, Backing Bean, faces-config, and one Xpages form. Let's get right into the JSF part and continue on to Xpages...



JSF JavaBean

[CODE]
public class perInfo {

String uname;
String firstName;
String lastName;


public perInfo(String firstName,String lastName,String uname) {
this.uname = uname;
this.firstName = firstName;
this.lastName = lastName;

}

public String getUname() {
return uname;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

}

}
[/CODE]



JSF Backing Bean

[CODE]

package roseindia;
import java.sql.*;
import java.util.*;

public class TableBean {

Connection con ;
Statement ps;
ResultSet rs;
private List perInfoAll = new ArrayList();

public List getperInfoAll() {
int i = 0;
try
{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/userdetails",
"root","root");

ps = con.createStatement();
rs = ps.executeQuery("select * from user");
while(rs.next()){
System.out.println(rs.getString(1));
perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2)
,rs.getString(3)));
i++;

}

}
catch (Exception e)
{
System.out.println("Error Data : " + e.getMessage());
}
return perInfoAll;
}

[/CODE]


JSF faces-config


[CODE]

<?xml version="1.0"?>
<faces-config>
<managed-bean>
<managed-bean-name>tableBean</managed-bean-name>
<managed-bean-class>roseindia.TableBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

</faces-config>

[/CODE]


JSF Form


[CODE]

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<f:view><html>
<head>

</head>
<body>
<center>
<br><br><br>
<h:dataTable id="dt1" value="#{tableBean.perInfoAll}" var="item" bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3" rows="4" width="50%" dir="LTR" frame="hsides" rules="all" summary="This is a JSF code to create dataTable." >

<f:facet name="header">
<h:outputText value="This is 'dataTable' demo" />
</f:facet>

<h:column>
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText style="" value="#{item.firstName}" ></h:outputText>
</h:column>

<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{item.lastName}"></h:outputText>
</h:column>

<h:column>
<f:facet name="header">
<h:outputText value="Username"/>
</f:facet>
<h:outputText value="#{item.uname}"></h:outputText>
</h:column>

<f:facet name="footer">
<h:outputText value="The End" />
</f:facet>

</h:dataTable><br>


</center>
</body></html></f:view>

[/CODE]


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>
==================================================================>>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>

As we enter this next phase, I would like to direct your attention to a demo application that is shipped with Domino Desginer 8.5.2, SiteFinder Demo... We will make use of existing view data to load to our Xpage. Let us continue...

Xpages JavaBean

[CODE]

/**

* Program: SiteDetails.java

* Created from Copy: 2011.09.28.12.20.AM

* JavaBean to load Site Details into Xpages

*/

package com.dokoll.solutions.inc.developement.jsf.test;


/**

* @author Dököll Solutions, Inc.

* @version 2011.09.27.3.29.AM

*

*/


public class SiteDetails {


String SiteName, SiteNumber, Directions;


/**

* @return the siteName

*/

public String getSiteName() {

return SiteName;

}


 

 

 

/**

* @param siteName the siteName to set

*/

public void setSiteName(String siteName) {

SiteName = siteName;

}


 

 

 

/**

* @return the siteNumber

*/

public String getSiteNumber() {

return SiteNumber;

}


 

 

 

/**

* @param siteNumber the siteNumber to set

*/

public void setSiteNumber(String siteNumber) {

SiteNumber = siteNumber;

}


 

 

 

/**

* @return the directions

*/

public String getDirections() {

return Directions;

}


 

 

 

/**

* @param directions the directions to set

*/

public void setDirections(String directions) {

Directions = directions;

}


 

 

 

public SiteDetails(String SiteName, String SiteNumber, String Directions) {

this.SiteName = SiteName;

this.SiteNumber = SiteNumber;

this.Directions = Directions;


}


}


[/CODE]



Xpages Backing Bean


[CODE]


/**

* Program: NotesDatabaseBackingBean.java

* Created from Copy: 2011.09.28.12.29.AM

* Backing Bean to load Site Details into Xpages

*/

package com.dokoll.solutions.inc.developement.jsf.test;


/**

* @author Dököll Solutions, Inc.

* @version 2011.09.28.12.29.AM

*

*/

//import java.sql.*;

import java.util.*;

import javax.faces.context.FacesContext;

import lotus.domino.View;

import lotus.domino.local.Database;

import lotus.domino.local.Document;


public class NotesDatabaseBackingBean {


//Connection con;

//Statement ps;

//ResultSet rs;

private List<SiteDetails> SiteInfo = new ArrayList<SiteDetails>();


public List<SiteDetails> getSiteData() {

int i = 0;

//Entering Try catch

System.out.println("Entering Try catch...");

try {


// get the current database being used, Faces style

Database database = (Database) FacesContext.getCurrentInstance()

.getApplication().getVariableResolver().resolveVariable(

FacesContext.getCurrentInstance(), "database");

System.out.println("Database Obtained..." + database);

System.out.println("Getting a database connection... ");


//Find the view in question

View view = database.getView("SiteListings");

System.out.println("View Obtained..." + view);


Document sDoc;

Document ndoc;


sDoc = (Document) view.getFirstDocument();

System.out.println("Document Obtained..." + sDoc);





while (sDoc !=null) {

System.out.println(sDoc.getItemValueString("SiteName"));

SiteInfo.add(i, new SiteDetails(sDoc.getItemValueString("SiteName"),sDoc.getItemValueString("SiteNumber"),sDoc.getItemValueString("Directions")));

i++;


//Get the next document in the view and store to the placeholder

ndoc = (Document) view.getNextDocument(sDoc);

//recycle the doc object to preserve memory

sDoc.recycle();

//set the doc object equal to the placeholder

sDoc = ndoc;


}


} catch (Exception e) {

System.out.println("Error Data : " + e.getMessage());

}

return SiteInfo;

}


}


[/CODE]



Xpages faces-config

[CODE]

<managed-bean>

<managed-bean-name>NotesDatabaseBackingBean</managed-bean-name>

<managed-bean-class> com.dokoll.solutions.inc.developement.jsf.test.NotesDatabaseBackingBean

</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

</managed-bean>

[/CODE]



Xpages Form

[CODE]

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">


<xp:dataTable rows="5" id="siteTable" var="contact" value="#{javascript:NotesDatabaseBackingBean.getSiteData()}"

style="width:50%">

<xp:this.facets>

<xp:pager layout="Previous Group Next" xp:key="header"

id="pager1" for="siteTable">

</xp:pager>

<xp:pager layout="Previous Group Next" xp:key="footer"

id="pager2" for="siteTable" partialRefresh="true">

</xp:pager>

</xp:this.facets>

<xp:column id="siteNameColumn">

<xp:text escape="true" id="siteNameField"

value="#{contact.siteName}">

</xp:text>

</xp:column>

<xp:column id="siteNumberColumn">

<xp:text escape="true" id="siteNumberField"

value="#{contact.siteNumber}">

</xp:text>

</xp:column>

<xp:column id="directionsColumn">

<xp:text escape="true" id="directionsField"

value="#{contact.directions}">

</xp:text>

</xp:column>

</xp:dataTable>

</xp:view>


[/CODE]

And that's all there is to it... I do recommend writing a separate method to run the SQL. This was an attempt to show how we can grab already available JSF samples to build Xpages Apps with Java code.

Happy Coding:-)


Feedback number WEBB8M59TH created by ~Elizabeth Ekfanalyjip on 09/28/2011

Status: Open
Comments:





Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS